package com.lwq.view;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BoxLayout;
import javax.swing.JPanel;

import com.lwq.controller.ProjectController;


public class CreateNodeDialog extends Frame
{
	private JPanel mSouthPanel = null;
	private JPanel mCenterPanel = null;
	private Button mOkBtn = null;
	private BoxLayout boxLayout = null;
	private TextField mNodeNameTf = null;
	private String mName = null;
	private GetNameListener mListener = null;

	public CreateNodeDialog(String lable,GetNameListener listener){
		super(lable);
		mListener = listener;
		setLayout(new BorderLayout());
		setEnabled(true);
		setVisible(true);
		setBounds(200, 200, 400, 300);
		mSouthPanel = new JPanel();
		mSouthPanel.setEnabled(true);
		mSouthPanel.setVisible(true);
		mCenterPanel = new JPanel();
		mCenterPanel.setEnabled(true);
		mCenterPanel.setVisible(true);
		
		boxLayout = new BoxLayout(mCenterPanel, BoxLayout.Y_AXIS); 
		mCenterPanel.setLayout(boxLayout);
		
//		mSouthPanel.setBorder(new MatteBorder(2, 0, 0, 0, Color.lightGray));
		add(mCenterPanel,"Center");
		add(mSouthPanel,"South");
		addWindowListener(new WindowAdapter()
		{
			public void windowClosing(WindowEvent evt)
			{
				CreateNodeDialog.this.setVisible(false); 
				CreateNodeDialog.this.dispose(); 
			}
		});
		mOkBtn = new Button("ok");
		mOkBtn.setVisible(true);

		mSouthPanel.add(mOkBtn);
		addContent();
		setEvent();
	}
	
	private void addContent(){
		JPanel panel = null;
		panel = new JPanel();
		panel.add(new Label("Name"));
		mNodeNameTf = new TextField(30);
		panel.add(mNodeNameTf);
		addLine(panel);
		
	}
	
	private void addLine(JPanel panel){
		mCenterPanel.add(panel);
	}
	
	private void setEvent(){
		mOkBtn.addActionListener(new ActionListener()
		{
			@Override
			public void actionPerformed(ActionEvent arg0)
			{
				if(mListener != null){
					mListener.getDate(mNodeNameTf.getText());
				}
				CreateNodeDialog.this.setVisible(false); 
				CreateNodeDialog.this.dispose();
			}
		});
	}
	
	
	public interface GetNameListener{
		public void getDate(String name);
	}
}
